#include "threadpool.hpp"
#include "Task.hpp"
bool ConnectSql()
{
    std::cout << "Sql conecting" << std::endl;
    int a = rand() % 20;
    if (a % 3 == 0)
    {
        return true;
    }
    else
        return false;
}
bool ConnectSqld()
{
    std::cout << "Sqld conecting" << std::endl;
    return true;
}
bool debug()
{
    std::cout << "Debuging" << std::endl;

    int a = rand() % 20;
    if (a % 3 == 0)
    {
        return true;
    }
    else
        return false;
}
using func = std::function<bool()>;
int main()
{
    sleep(3);
    std::unique_ptr<threadpool<func>> pool = std::make_unique<threadpool<func>>(3);
    EnableFile();
    pool->InitThreadPool();
    pool->Start();
    while (1)
    {
        sleep(1);
        pool->Enqueue(ConnectSqld);
        pool->Enqueue(ConnectSql);
        pool->Enqueue(debug);
        if (pool->ReadyToStart())
        {
            std::cout<<"Start"<<std::endl;
            break;
        }
    }
    pool->Stop();
    std::cout<<"Starting--------------------------------------------------"<<std::endl;
    pool->Wait();


    
    threadpool<func>::Getinstance();
    threadpool<func>::Getinstance()->Start();
    threadpool<func>::Getinstance()->Stop();
    threadpool<func>::Getinstance()->Wait();


    

    return 0;
}
